package enumtest;

public enum TestDemo {
    RED("红色",1),
    GREEN("绿色",2),
    BLACK("黑色",3);
    public String name;
    public int val;
     TestDemo(String name,int val) {
        this.name = name;
        this.val = val;
    }

    public static void main(String[] args) {
        TestDemo[] testDemos = TestDemo.values();
        for (int i = 0; i < testDemos.length; i++) {
            System.out.println(testDemos[i].name+" "+testDemos[i].val );
        }
    }
    public static void main3(String[] args) {
        TestDemo[] testDemos = TestDemo.values();
        for (int i = 0; i < testDemos.length; i++) {
            System.out.println(testDemos[i] + " " + testDemos[i].ordinal());
        }
        System.out.println("===============");
        TestDemo testDemo = TestDemo.valueOf("RED");
        System.out.println("testDemo="+testDemo);
        System.out.println("===============");
        System.out.println(RED.compareTo(GREEN));
    }
    public static void main1(String[] args) {
        TestDemo testDemo = TestDemo.RED;
        switch (testDemo) {
            case RED -> System.out.println("RED");
            case GREEN -> System.out.println("GREEN");
            case BLACK -> System.out.println("BLACK");
        }
    }
}

